package com.song.shop.rocketmq;

import org.apache.rocketmq.client.exception.MQClientException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 *
 * @author: Song Yinhui
 * @Date: 2018/12/7 17:40
 */
@Component
public class MqCustomer {

    @Autowired
    private List<ICustomerCallBack> handlers ;

    @Autowired
    private RocketmqService rocketmqService;

    @PostConstruct
    public void init() throws MQClientException {
        System.out.println("-------------------------");
        for (ICustomerCallBack callBack : handlers){
            //为所有实现ICustomer接口的类初始化一个mq客户端，一个Topic实现一次ICustomer
            System.out.println("topic:"+callBack.getTopic());
            rocketmqService.subTopic(callBack.getTopic() , callBack);
        }
        System.out.println("-------------------------");
    }
}
